//
// Description: 1109. 航班预订统计
// Created by Loading on 2021/8/31.
//

#include <bits/stdc++.h>

using namespace std;

vector<int> corpFlightBookings(vector<vector<int>> &bookings, int n) {
    /* 对于区间的频繁操作或区间较大，使用差分数组技巧 */
    // 差分数组
    vector<int> d(n + 1);
    for (auto &booking : bookings) {
        d[booking[0] - 1] += booking[2];
        d[booking[1]] -= booking[2];
    }
    // 差分数组修改为其前缀和
    d.pop_back();
    for (int i = 1; i < n; ++i) {
        d[i] += d[i - 1];
    }

    return d;
}

int main() {
    vector<vector<int>> bookings = {{1, 2, 10},
                                    {2, 3, 20},
                                    {2, 5, 25}};
    int n = 5;
    vector<int> res = corpFlightBookings(bookings, n);
    for (auto &x : res) {
        cout << x << " ";
    }
    cout << endl;

    return 0;
}